<template>
  <div class="subject-range-wrap">
    <el-select v-model="startCode" filterable style="width: 160px" placeholder="开始科目" size="small" @change="subjectChange">
      <el-option
        v-for="item in subjectTree"
        :disabled="endCode < item.subjectCode"
        :key="item.subjectCode"
        :label="item.subjectCode + ' - ' + item.subjectName"
        :value="item.subjectCode">
        <span :style="{paddingLeft: item.sub ? '2em':''}">{{ item.subjectCode }} - {{ item.subjectName }}</span>
      </el-option>
    </el-select>
    <span>~</span>
    <el-select v-model="endCode" filterable style="width: 160px" placeholder="结束科目" size="small" @change="subjectChange">
      <el-option
        v-for="item in subjectTree"
        :disabled="startCode > item.subjectCode"
        :key="item.subjectCode"
        :label="item.subjectCode + ' - ' + item.subjectName"
        :value="item.subjectCode">
        <span :style="{paddingLeft: item.sub ? '2em':''}">{{ item.subjectCode }} - {{ item.subjectName }}</span>
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'SubjectRangeSelect',
  props: {
    startCode: {
      type: String,
      default: ''
    },
    endCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
    }
  },
  computed: {
    ...mapGetters([
      'subjectTree'
    ])
  },
  created() {
  },
  methods: {
    subjectChange() {
      this.$emit('change', [this.startCode, this.endCode])
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .subject-range-wrap {
    display: inline-block;
  }
</style>
